package com.tjvib.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.tjvib.R;
import com.tjvib.util.Manager.AppManager;
import com.tjvib.util.PressUtil;

public class TitleLayout extends RelativeLayout {

    private ImageView tit_iv_back;
    private TextView tit_tv_tit;


    public TitleLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
        initAttrs(context, attrs);
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.layout_title, this);

        tit_iv_back = findViewById(R.id.tit_iv_back);
        tit_tv_tit = findViewById(R.id.tit_tv_tit);

        PressUtil.setPressChange(context, tit_iv_back);
        tit_iv_back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
//                ((Activity)getContext()).finish();
                AppManager.getInstance().finishActivity();
            }
        });
    }

    private void initAttrs(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TitleLayout);
        String title = typedArray.getString(R.styleable.TitleLayout_tit_title);
        tit_tv_tit.setText(title);
        typedArray.recycle();
    }


    /**
     * 设置标题文字
     */
    public void setTitle(String s) {
        tit_tv_tit.setText(s);
    }
}